const input = (element, binding, vnode) => {
    return () => {
        const value = element.value
        const numbers = '1234567890'
        if (value !== undefined) {
            let r = ''
            for (let i = 0; i < value.length; i++) {
                const n = value[i]
                if (numbers.includes(n)) {
                    r += n
                }
            }

            if (value[0] === '-' && r.length <= 1) {
                r = ''
            }
            element.value = r
        }
    }
}

export default {
    bind(element, binding, vnode) {
        const e = element.tagName === 'INPUT' ? element : element.querySelector('input')
        const handler = input(e, binding, vnode)
        e.addEventListener('input', handler, false)
    },
}
